package org.tsdb;

import org.influxdb.InfluxDB;
import org.influxdb.impl.InfluxDBImpl;


import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Point;
import java.util.concurrent.TimeUnit;

public class InfluxdbDemo {
        public static void main(String[] args) {
            // 创建 InfluxDB 客户端对象
            InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:8086", "username", "password");


            // 构建数据点
            Point point = Point.measurement("cpu")
                    .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
                    .tag("host", "server1")
                    .addField("usage", 80)
                    .addField("unUsage" ,20)
                    .build();

            // 写入数据到 InfluxDB
            influxDB.write("my_database", "autogen", point);

            // 关闭 InfluxDB 客户端连接
            influxDB.close();
        }
    }

